package com.demo2do.jit;

import android.app.Application;
import android.content.Context;

import com.demo2do.jit.injection.component.ApplicationComponent;
import com.demo2do.jit.injection.component.DaggerApplicationComponent;
import com.demo2do.jit.injection.module.ApplicationModule;
import com.demo2do.jit.injection.module.RemoteModule;
import com.netease.nis.bugrpt.CrashHandler;


/**
 * Created by Wilson
 */
public class JitApplication extends Application {

    private static final String TAG = JitApplication.class.getSimpleName();

    ApplicationComponent mApplicationComponent;

    private String cookie;

    @Override
    public void onCreate() {
        super.onCreate();

        // inject
        injectComponent();

        // onCreate bugrpt crash
        CrashHandler.init(this);

    }

    private void injectComponent() {
        // build the application component graph
        mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .remoteModule(new RemoteModule())
                .build();
        // inject JitApplication fields
        mApplicationComponent.inject(this);
    }



    public ApplicationComponent getComponent() {
        return mApplicationComponent;
    }

    public static JitApplication get(Context context) {
        return (JitApplication) context.getApplicationContext();
    }

    public void setCookie(String cookie) {
        this.cookie = cookie;
    }

    public String getCookie() {
        return this.cookie;
    }

}
